/*
 * Title: WADS
 * Description: Web-based Auto flow Documents System
 * Copyright: 2007
 * Company: CoE
 * @author: Mr.Nattasan Wang-Aphisit
 * @version 1.1
 */

package wads.app;

import java.io.File;
import javax.swing.filechooser.FileFilter;

public class DiagramFilter extends FileFilter {

  private String acceptableExtensions[];
  private String description = "Organization File";

  public DiagramFilter(String ext){
    super();
    acceptableExtensions = new String[1];
    acceptableExtensions[0] = ext;
  }

  public DiagramFilter(String ext[], String desc){
    super();
    this.description = desc;
    acceptableExtensions = ext;
  }

  // Accept all directories and all files with extension specified
  public boolean accept(File f) {

    if (f.isDirectory()) {
      return true;
    }

    String s = f.getName();
    int i = s.lastIndexOf('.');

    if (i > 0 &&  i < s.length() - 1) {
      String extension = s.substring(i+1).toLowerCase();
      for (int j=0; j<acceptableExtensions.length; j++){
        if (acceptableExtensions[j].equals(extension))
          return true;
        else
          return false;
      }
    }

    return false;
  }

  // The description of this filter
  public String getDescription() {
    return description;
  }

}// end of Diagram Editor Class
